package com.coc.ofmylistener.event.configration;

import com.coc.ofmylistener.event.DatabaseEventStore;
import com.coc.ofmylistener.event.EventHandlerManager;
import com.coc.ofmylistener.event.EventPublisher;
import com.coc.ofmylistener.event.EventStore;
import com.coc.ofmylistener.event.spring.EventHandlerBeanPostProcessor;
import com.coc.ofmylistener.event.support.AsynSupportEventPublisher;
import com.coc.ofmylistener.event.support.SimpleEventHandlerManager;
import com.coc.ofmylistener.event.support.SimpleEventPublisher;
import com.coc.ofmylistener.listenner.TestListeners;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.wiring.BeanConfigurerSupport;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;
import java.sql.SQLException;

@Configuration
public class BeanConfigration  extends BeanConfigurerSupport implements BeanFactoryAware {

    @Bean
    public EventHandlerManager eventHandlerManager() {
        return new SimpleEventHandlerManager();
    }

    @Bean
    public EventHandlerBeanPostProcessor eventHandlerBeanPostProcessor(EventHandlerManager eventHandlerManager){
        return new EventHandlerBeanPostProcessor(eventHandlerManager);
    }

    @Bean
    public EventStore szPbEventStore(DataSource dataSource) throws SQLException {
        return new DatabaseEventStore(dataSource);
    }

    @Bean(name = "asynSupportEventPublisher")
    public EventPublisher szPbEventPublisher(EventHandlerManager ehm, EventStore es){
        return new AsynSupportEventPublisher(ehm, es);
    }

    @Bean(name = "simpleEventPublisher")
    public EventPublisher simlpePublish (EventHandlerManager ehm) {
        return new SimpleEventPublisher(ehm);
    }

    @Bean
    public TestListeners getTestListeners(){
        return new TestListeners();
    }

}
